from werkzeug.datastructures import Headers
from flask import Response


#   ctx.set('Access-Control-Allow-Origin', 'https://velog.io');
#   ctx.set('Access-Control-Allow-Credentials', (true: any));
class MyResponse(Response):
    def __init__(self, response=None, **kwargs):
        kwargs['headers'] = ''
        headers = kwargs.get('headers')
        # 跨域控制 
        origin = ('Access-Control-Allow-Origin', '*')
        Credentials = ('Access-Control-Allow-Credentials', 'true')
        if headers:
            headers.add(*origin)
            headers.add(*Credentials)
        else:
            headers = Headers([origin, Credentials])
        kwargs['headers'] = headers
        return super().__init__(response, **kwargs)
